<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta http-equiv="X-UA-Compatible" content="ie=edge" />
		<link rel="stylesheet" href="/static/index.css" />
		<title>单文件上传</title>
	</head>

	<body>
		<h4>单文件上传</h4>
		<a href="/" style="color: crimson;">返回首页</a>
		<form id="uploadForm" action="" method="post" enctype="multipart/form-data">
			<p>
				<input type="file" name="file" />
				<input type="submit" value="提交" id="submit" />
			</p>
			<p>
				<a href="/filelist" style="color: crimson;">查看文件列表</a>
			</p>
		</form>
		<div class="pop">
			<div class="loader"></div>
		</div>
	</body>
	<script src="/static/jquery.js"></script>
	<script>
		$(function() {
			let time = null
			$('#submit').click(function(event) {
				event.preventDefault()
				$('.pop').show()
				$.ajax({
					type: 'POST',
					url: '/upload',
					processData: false,
					contentType: false,
					data: new FormData($('#uploadForm')[0]),
					success: function(res) {
						setTimeout(() => {
							$('.pop').hide()
						}, 600)
						alert(res.message)
					},
					error: function(err) {
						alert('上传失败！')
					},
				})
			})
		})
	</script>
</html>
